package cn.itcast.demo.controller;

import cn.itcast.demo.pojo.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Arrays;
import java.util.Date;

@Controller
public class HelloController {

    @GetMapping("hello")
    public String sayHello(Model model){
        model.addAttribute("yun9","very well");
        return "hello01";//templates/hello01.html
    }

    @GetMapping("student")
    public String showStudent(Model model){
        Student student = new Student();
        student.setId("10086");
        student.setName("刘德华");
        student.setAge(50);

        model.addAttribute("student",student);

        return "student";//templates/hello01.html
    }

    @GetMapping("show1")
    public String show1(Model model){

        model.addAttribute("info","<h2>今天天冷，</h2>");

        return "show1";//templates/hello01.html
    }

    @GetMapping("show2")
    public String show2(Model model){
        model.addAttribute("today", new Date());
        return "show2";
    }

    @GetMapping("show3")
    public String show3(Model model){

        model.addAttribute("info","hello everyone");
        return "show3";
    }

    @GetMapping("show4")
    public String show4(Model model){

        model.addAttribute("age",30);
        return "show4";
    }

    @GetMapping("show5")
    public String show5(Model model){

        Student student1 = new Student();
        student1.setId("10086");
        student1.setName("刘德华");
        student1.setAge(50);

        Student student2 = new Student();
        student2.setId("10087");
        student2.setName("刘德华");
        student2.setAge(50);

        Student student3 = new Student();
        student3.setId("10089");
        student3.setName("刘德华");
        student3.setAge(50);

        model.addAttribute("students", Arrays.asList(student1,student2,student3));


        return "show5";
    }

    @GetMapping("show6")
    public String show6(Model model){

        model.addAttribute("age",30);
        model.addAttribute("name","刘德华");
        Student student3 = new Student();
        student3.setId("10089");
        student3.setName("刘德华");
        student3.setAge(50);

        model.addAttribute("student",student3);

        return "show6";
    }
}
